#!/bin/sh
#
# Set Client in Passive mode.
# Run simple backups and restore them.
#
TestName="backup-susan-passive-test"
JobName=backup
. scripts/functions

scripts/cleanup
scripts/copy-confs

#
# Zap out any schedule in default conf file so that
#  it doesn't start during our test
#
outf="$tmp/sed_tmp"
echo "s%  Schedule =%# Schedule =%g" >${outf}
cp ${conf}/susan-dir.conf $tmp/1
sed -f ${outf} $tmp/1 >${conf}/susan-dir.conf

dircfg=$conf/susan-dir.conf
$bperl -e "add_attribute('$dircfg', 'passive', 'Yes', 'Client')"

fdcfg=$conf/susan-fd.conf
$bperl -e "add_attribute('$fdcfg', 'Compatible', 'No', 'FileDaemon')"

change_jobname BackupClient1FileList $JobName

# Directory to backup.
# This directory will be created by setup_data().
BackupDirectory="${tmp}/data"

# Use a tgz to setup data to be backed up.
# Data will be placed at "${tmp}/data/".
setup_data data/small.tgz

# the default fileset FS_TESTJOB backups all file and directories defined in "${tmp}/file-list".
echo "${BackupDirectory}" >${tmp}/file-list


start_test

cat <<END_OF_DATA >$tmp/bconcmds
@$out /dev/null
messages
@$out $tmp/log1.out
setdebug level=100 storage=File
run job=$JobName yes
wait
messages
@#
@# now do a restore
@#
@$out $tmp/log2.out
restore where=$tmp/susan-restores select all done
yes
wait
messages
quit
END_OF_DATA

run_susan
check_for_zombie_jobs storage=File

#
# Now do a second backup after making a few changes
#
change_files

cat <<END_OF_DATA >$tmp/bconcmds
@$out /dev/null
messages
@$out $tmp/log1.out
@#setdebug level=100 storage=File
run job=$JobName yes
wait
messages
@#
@# now do a restore
@#
@$out $tmp/log2.out
restore where=$tmp/susan-restores select all done
yes
wait
messages
quit
END_OF_DATA

run_bconsole
check_for_zombie_jobs storage=File
stop_susan

check_two_logs
check_restore_diff
end_test
